package com.cskaoyan.controller;

import com.cskaoyan.bean.BaseRespVo;
import com.cskaoyan.bean.Topic;
import com.cskaoyan.bean.params.BaseParam;
import com.cskaoyan.bean.vo.promotion_vo.TopicListVO;
import com.cskaoyan.bean.vo.promotion_vo.TopicReadVO;
import com.cskaoyan.service.WxTopicService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("wx/topic")
public class WxTopicController {
    @Autowired
    WxTopicService wxTopicService;

    @RequestMapping("list")
    public BaseRespVo topList(@RequestParam(value = "page") Integer page, @RequestParam(value = "limit") Integer limit) {
        BaseParam baseParam = new BaseParam();
        baseParam.setPage(page);
        baseParam.setLimit(limit);
        TopicListVO listVO = wxTopicService.list(baseParam);
        return BaseRespVo.ok(listVO);
    }

    @GetMapping("detail")
    public BaseRespVo topDetail(@RequestParam(value = "id") Integer id) {
        Topic topic = new Topic();
        topic.setId(id);
        TopicReadVO topicReadVO = wxTopicService.detail(topic.getId());
        return BaseRespVo.ok(topicReadVO);
    }

    @GetMapping("related")
    public BaseRespVo topRelated(@RequestParam(value = "id") Integer id) {
        Topic topic = new Topic();
        topic.setId(id);
        List<Topic> listVO = wxTopicService.related(topic.getId());
        TopicListVO topicListVO = new TopicListVO();
        topicListVO.setList(listVO);
        return BaseRespVo.ok(topicListVO);
    }
}
